package com.guoyw.leetcode.question.everyday.Y2021.M03;

/**
 * @Description: 83. 删除排序链表中的重复元素
 * @Author: guoyw
 * @CreateDate: 2021/3/26 2:02 下午
 * @Version: 1.0
 */

public class Day26_C83 {

  public ListNode deleteDuplicates(ListNode head) {
    if(head == null){
      return head;
    }
    ListNode cur = head;
    ListNode result = cur;
    while (cur.next != null) {
        if (cur.next.val == cur.val) {
          if(cur.next.next != null){
            cur.next = cur.next.next;
          }else {
            cur.next = null;
          }
        }else {
            cur = cur.next;
        }
    }
    return result;
  }


  public class ListNode {
    int val;
    ListNode next;

    ListNode() {
    }

    ListNode(int val) {
      this.val = val;
    }

    ListNode(int val, ListNode next) {
      this.val = val;
      this.next = next;
    }
  }
}
